package roles;

import avenue.MyWindowEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.persistence.EntityManager;
import model.DBManager;
import model.RolePermission;

public class RolePermissionDialogueForm extends javax.swing.JFrame {

    public RolePermissionDialogueForm(RolePermission rp) {
        em = DBManager.em;
        if (!em.getTransaction().isActive()){
            em.getTransaction().begin();
        }
        rolePermission1 = rp;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        rolePermission2 = rolePermission1;
        cancelButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        roleNameLabel = new javax.swing.JLabel();
        roleNameTF = new javax.swing.JTextField();
        canCreateLabel = new javax.swing.JLabel();
        canRetrieveLabel = new javax.swing.JLabel();
        stationLevelAccessLabel = new javax.swing.JLabel();
        canUpdateLabel = new javax.swing.JLabel();
        canDeleteLabel = new javax.swing.JLabel();
        separator = new javax.swing.JSeparator();
        stationLevelCheckBox = new javax.swing.JCheckBox();
        canCreateCheckBox = new javax.swing.JCheckBox();
        canRetrieveCheckBox = new javax.swing.JCheckBox();
        canUpdateCheckBox = new javax.swing.JCheckBox();
        canDeleteCheckBox = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Διαχείριση Δικαιώματος");

        cancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cancel.gif"))); // NOI18N
        cancelButton.setText("Ακυρο");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.gif"))); // NOI18N
        saveButton.setText("Αποθήκευση");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        roleNameLabel.setText("Όνομα Ρόλου:");

        roleNameTF.setEditable(false);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, rolePermission2, org.jdesktop.beansbinding.ELProperty.create("${roleId.roleName}"), roleNameTF, org.jdesktop.beansbinding.BeanProperty.create("text"), "roleName");
        bindingGroup.addBinding(binding);

        canCreateLabel.setText("Can Create:");

        canRetrieveLabel.setText("Can Retrieve:");

        stationLevelAccessLabel.setText("Station Level Access:");

        canUpdateLabel.setText("Can Update:");

        canDeleteLabel.setText("Can Delete:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, rolePermission2, org.jdesktop.beansbinding.ELProperty.create("${stationLevelAccess}"), stationLevelCheckBox, org.jdesktop.beansbinding.BeanProperty.create("selected"), "stationLevelAccess");
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, rolePermission2, org.jdesktop.beansbinding.ELProperty.create("${canCreate}"), canCreateCheckBox, org.jdesktop.beansbinding.BeanProperty.create("selected"), "canCreate");
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, rolePermission2, org.jdesktop.beansbinding.ELProperty.create("${canRetrieve}"), canRetrieveCheckBox, org.jdesktop.beansbinding.BeanProperty.create("selected"), "canRetrieve");
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, rolePermission2, org.jdesktop.beansbinding.ELProperty.create("${canUpdate}"), canUpdateCheckBox, org.jdesktop.beansbinding.BeanProperty.create("selected"), "canUpdate");
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, rolePermission2, org.jdesktop.beansbinding.ELProperty.create("${canDelete}"), canDeleteCheckBox, org.jdesktop.beansbinding.BeanProperty.create("selected"), "canDelete");
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cancelButton)
                                .addGap(18, 18, 18)
                                .addComponent(saveButton))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(roleNameLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(roleNameTF, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(canDeleteLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(canDeleteCheckBox))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(canUpdateLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(canUpdateCheckBox))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(canRetrieveLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(canRetrieveCheckBox))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(canCreateLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(canCreateCheckBox))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(stationLevelAccessLabel)
                                    .addGap(18, 18, 18)
                                    .addComponent(stationLevelCheckBox))))
                        .addGap(0, 302, Short.MAX_VALUE))
                    .addComponent(separator))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(18, 18, 18)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(roleNameLabel)
                                                    .addComponent(roleNameTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(18, 18, 18)
                                                .addComponent(separator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                                                .addComponent(stationLevelAccessLabel))
                                            .addGroup(layout.createSequentialGroup()
                                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(stationLevelCheckBox)))
                                        .addGap(18, 18, 18)
                                        .addComponent(canCreateLabel))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(0, 0, Short.MAX_VALUE)
                                        .addComponent(canCreateCheckBox)))
                                .addGap(18, 18, 18)
                                .addComponent(canRetrieveLabel))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(canRetrieveCheckBox)))
                        .addGap(18, 18, 18)
                        .addComponent(canUpdateLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(canUpdateCheckBox)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(canDeleteLabel)
                    .addComponent(canDeleteCheckBox))
                .addGap(42, 42, 42)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(saveButton))
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed

        // Διαχείριση παραθύρων
        MyWindowEvent we = new MyWindowEvent(this, WindowEvent.WINDOW_CLOSED,false);
        for (WindowListener l : this.getWindowListeners()) {
            l.windowClosed(we);
        }
        this.setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed

        // Διαχείριση παραθύρων
        MyWindowEvent we = new MyWindowEvent(this, WindowEvent.WINDOW_CLOSED,true);
        for (WindowListener l : this.getWindowListeners()) {
            l.windowClosed(we);
        }
        this.setVisible(false);
    }//GEN-LAST:event_saveButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox canCreateCheckBox;
    private javax.swing.JLabel canCreateLabel;
    private javax.swing.JCheckBox canDeleteCheckBox;
    private javax.swing.JLabel canDeleteLabel;
    private javax.swing.JCheckBox canRetrieveCheckBox;
    private javax.swing.JLabel canRetrieveLabel;
    private javax.swing.JCheckBox canUpdateCheckBox;
    private javax.swing.JLabel canUpdateLabel;
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel roleNameLabel;
    private javax.swing.JTextField roleNameTF;
    private model.RolePermission rolePermission2;
    private javax.swing.JButton saveButton;
    private javax.swing.JSeparator separator;
    private javax.swing.JLabel stationLevelAccessLabel;
    private javax.swing.JCheckBox stationLevelCheckBox;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    EntityManager em;
    RolePermission rolePermission1;
    
}
